/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Login.java
 *
 * Created on 1/Dez/2011, 17:33:04
 */
package desint;

import java.awt.CardLayout;

/**
 *
 * @author lenny
 */
public class Login extends javax.swing.JPanel {
    
     public JanelaPrincipal jp;
     private CardLayout cardlayout;
     public boolean  ok;
    
    /** Creates new form Login */
    public Login() {
        initComponents();
        ok=false;
        msg_error.setText(" ");
      
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        roundPanel1 = new desint.RoundPanel();
        username = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        password = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        enviar = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        msg_error = new javax.swing.JLabel();
        gestGymLogo = new javax.swing.JLabel();
        imagem = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));

        jLayeredPane1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setText("Username");

        jLabel2.setText("Password");

        enviar.setText("Entrar");
        enviar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                enviarMouseClicked(evt);
            }
        });

        cancel.setText("Cancel");

        msg_error.setForeground(new java.awt.Color(255, 51, 51));
        msg_error.setText("msg erro");

        javax.swing.GroupLayout roundPanel1Layout = new javax.swing.GroupLayout(roundPanel1);
        roundPanel1.setLayout(roundPanel1Layout);
        roundPanel1Layout.setHorizontalGroup(
            roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, roundPanel1Layout.createSequentialGroup()
                .addContainerGap(130, Short.MAX_VALUE)
                .addComponent(cancel)
                .addGap(28, 28, 28)
                .addComponent(enviar)
                .addGap(74, 74, 74))
            .addGroup(roundPanel1Layout.createSequentialGroup()
                .addGap(76, 76, 76)
                .addGroup(roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(39, 39, 39)
                .addGroup(roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(password, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(username, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(74, Short.MAX_VALUE))
            .addGroup(roundPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(msg_error)
                .addContainerGap(300, Short.MAX_VALUE))
        );
        roundPanel1Layout.setVerticalGroup(
            roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(roundPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(msg_error)
                .addGap(33, 33, 33)
                .addGroup(roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addGroup(roundPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enviar)
                    .addComponent(cancel))
                .addGap(31, 31, 31))
        );

        roundPanel1.setBounds(310, 200, 370, 230);
        jLayeredPane1.add(roundPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        gestGymLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gestgym_logo.png"))); // NOI18N
        gestGymLogo.setBounds(50, 40, 350, 90);
        jLayeredPane1.add(gestGymLogo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        imagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/young-woman.jpg"))); // NOI18N
        imagem.setBounds(50, 90, 290, 390);
        jLayeredPane1.add(imagem, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 830, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 540, Short.MAX_VALUE)
        );

        jPanel1.setBounds(0, 10, 830, 540);
        jLayeredPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 817, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void enviarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_enviarMouseClicked
        cardlayout = (CardLayout) (jp.menus.getLayout());
        
        boolean ok = false;
        
        if (username.getText().equals("a") && password.getText().equals("a")){
            ok=true;
           cardlayout.show(jp.menus, "menuAdministrador");
           jp.perfilText.setText("Administrador");
           jp.setTexto("Utilizadores");
           jp.setMenu(JanelaPrincipal.MENU_UTILIZADOR);
           jp.changeFirstCard(jp.MENU_UTILIZADOR);
        
        } else if (username.getText().equals("t") && password.getText().equals("t")) {
            ok=true;
            cardlayout.show(jp.menus, "menuTreinador"); 
            jp.perfilText.setText("Treinador");
            jp.setTexto("Agenda");
            jp.setMenu(JanelaPrincipal.MENU_AGENDA);
            jp.changeFirstCard(jp.MENU_AGENDA);
        
        } else if (username.getText().equals("f") && password.getText().equals("f")) {
            ok=true;
            cardlayout.show(jp.menus, "menuFuncionario"); 
            jp.perfilText.setText("Funcionario");
            jp.setTexto("Utilizadores");
            jp.setMenu(JanelaPrincipal.MENU_UTILIZADOR);
            jp.changeFirstCard(jp.MENU_UTILIZADOR);
        
        } else if (username.getText().equals("s") && password.getText().equals("s")) {
            ok=true;
            cardlayout.show(jp.menus, "menuSocio"); 
            jp.perfilText.setText("Socio");
            jp.setTexto("Agenda");
            jp.changeFirstCard(jp.MENU_AGENDA_SOCIO);
            jp.setMenu(JanelaPrincipal.MENU_AGENDA_SOCIO);
        } 
        
        
        if (ok){
             setVisible(false);
            jp.layers.setVisible(true);
        } else {
            msg_error.setText("Username e/ou password invalidas.");
        }
        
        
    }//GEN-LAST:event_enviarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancel;
    private javax.swing.JButton enviar;
    private javax.swing.JLabel gestGymLogo;
    private javax.swing.JLabel imagem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel msg_error;
    private javax.swing.JTextField password;
    private desint.RoundPanel roundPanel1;
    private javax.swing.JTextField username;
    // End of variables declaration//GEN-END:variables
}
